package com.bristua.common.controller;

import com.bristua.common.bean.Result;
import com.bristua.common.biz.AddAppIndexImgBiz;
import com.bristua.common.biz.AliFileUploadBiz;
import com.bristua.common.dao.TIndexImgMapper;
import com.bristua.common.enums.CommonCode;
import com.bristua.common.exception.BizException;
import com.bristua.common.model.TIndexImg;
import com.bristua.common.model.condition.TIndexImgExample;
import com.bristua.common.utils.HandleResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.net.BindException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;



@Controller
@Api(value="APP首页轮播图管理",tags={"APP首页轮播图管理"})
public class AppIndexImgUploadController {



    @Autowired
    private AddAppIndexImgBiz addAppIndexImgBiz;

    @Resource
    private TIndexImgMapper indexImgMapper;


    @ApiOperation("APP首页轮播图上传")
    @PostMapping(value="/admin/app/index/image/upload")
    @ResponseBody
    public Result addAppIndexImg(@RequestBody TIndexImg tIndexImg){
        addAppIndexImgBiz.addAppIndexImgBiz(tIndexImg);
        return HandleResultUtil.addSuccessResult();
    }

    @ApiOperation("APP首页轮播图查询")
    @PostMapping(value="/admin/app/index/image/query/{indexImgUrlId}")
    @ResponseBody
    public Result indexImgQuery(@PathVariable(value = "indexImgUrlId") String indexImgUrlId){
        TIndexImgExample tIndexImgExample = new TIndexImgExample();
        tIndexImgExample.setOrderByClause("sort_num asc");
        if(!"0".equals(indexImgUrlId)){
            tIndexImgExample.createCriteria().andIndexImgUrlIdEqualTo(indexImgUrlId);
        }
        return HandleResultUtil.querySuccessResult(indexImgMapper.selectByExampleWithBLOBs(tIndexImgExample));
    }


    @ApiOperation("APP首页轮播图删除")
    @PostMapping(value="/admin/app/index/image/del/{indexImgUrlId}")
    @ResponseBody
    public Result indexImgDel(@PathVariable(value = "indexImgUrlId") String indexImgUrlId){
        addAppIndexImgBiz.delAppIndexImg(indexImgUrlId);
        return HandleResultUtil.delSuccessResult();
    }


}
